<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router'; // 引入 useRouter
import { articleApi } from '@/apis/ArticleApi';
import LangScapeCard from '@/components/home/LangScapeCard.vue';
import PulsatingButton from '@/components/ui/pulsating-button';

let topList = ref();
const router = useRouter(); // 获取路由实例

const getList = async () => {
	let res = await articleApi.getTopList();
	topList.value = res.data;
};

onMounted(() => {
	getList();
});

const getArticleDetail = (id: number) => {
	// 跳转到文章详情页面
	router.push({ name: 'ArticleDetail', params: { id: id } });
};

const back = () => {
	router.back();
};
</script>
<template>
	<div class="container-tech-article" v-if="!$route.params.id">
		<LangScapeCard
			v-for="article in topList"
			:article="article"
			@articleId="getArticleDetail"
		></LangScapeCard>
	</div>
	<div v-else>
		<router-view></router-view>
		<PulsatingButton pulseColor="var(--theme-color)" duration="2s"class="back-btn" @click="back">返回</PulsatingButton>
	</div>
</template>

<style scoped lang="less">
.container-tech-article {
	padding: 20px;
	display: flex;
	flex-wrap: wrap;
	gap: 2.5vh;
	justify-content: center;
	.landscape-card-container {
		width: 80%;
	}
}

.back-btn {
	position: absolute;
	top: 18vh;
	right: 10vw;
	color: #21f9bf;
	font-size: 20px;
	cursor: pointer;
}
</style>
